package lc;

public class ValidPalindrome {
    public boolean isPalindrome(String s) {
        s = s.replaceAll("[^A-Za-z0-9]", "");
        s = s.toLowerCase();
        int i=0, j=s.length()-1;
        while (i<j) {
        	char head = s.charAt(i++);
			char tail = s.charAt(j--);
			if (head != tail) {
        		return false;
        	}
        }
    	return true;
    }

    public static void main(String ...strings) {
    	ValidPalindrome sol = new ValidPalindrome();
    	boolean palindrome = sol.isPalindrome("A man, a plan, a canal: Panama");
    	System.out.println(palindrome);
    	palindrome = sol.isPalindrome("race a car");
    	System.out.println(palindrome);
    	palindrome = sol.isPalindrome("1a2");
    	System.out.println(palindrome);
    	palindrome = sol.isPalindrome("r");
    	System.out.println(palindrome);
    }
}
